﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using FIFP.DashBoard.Helper;
using FIFP.DashBoard.ViewModel;
using FIFP.DashBoard.Model;
using Telerik.Windows.Controls.ScheduleView;
using System.Collections.Generic;

namespace FIFP.DashBoard.Converters
{
    public class ScheduleDragDropBehavior : ScheduleViewDragDropBehavior
    {
        public override bool CanDrop(DragDropState state)
        {
            Resource sourceResource = null;
            Resource destinationResource = null;

            Appointment ap = (Appointment)state.Appointment;
            FIFPAppointment appointment = (FIFPAppointment)state.Appointment;
            foreach (Resource resource in ap.Resources)
            {
                sourceResource = resource;
                break;
            }

            foreach (Slot s in state.DestinationSlots)
            {
                foreach (Resource resource in s.Resources)
                {
                    destinationResource = resource;
                    break;
                }
            }

            if (sourceResource == destinationResource && (appointment != null && !appointment.IsLinkedShutdownPlan))
                return true;
            else
                return false;
        }

        public override bool CanResize(DragDropState state)
        {
            FIFPAppointment appointment = (FIFPAppointment)state.Appointment;
            //if (appointment != null && (appointment.Start == appointment.OriginalStart && appointment.End <= appointment.OriginalEnd))
            if (appointment != null && (!appointment.IsAppointmentDelete && !appointment.IsLinkedShutdownPlan))
                return true;
            else
                return false;
        }

        #region CommentOut Code
        /*
        public override bool CanStartDrag(DragDropState state)
        {
            return true;
        }

        public override bool CanDrop(DragDropState state)
        {
            return true;
        }

        public override void Drop(DragDropState state)
        {
            Resource sourceResource = null; Resource destinationResource = null;
            IEnumerable<Slot> destinationSlot = state.DestinationSlots;
            foreach (Slot slot in destinationSlot)
            {
                foreach (Resource resource in slot.Resources)
                {
                    sourceResource = resource;
                    break;
                }
            }
            IEnumerable<IOccurrence> sourceSlot = state.DraggedAppointments;
            foreach (FIFPAppointment appointment in sourceSlot)
            {
                foreach (Resource resource in appointment.Resources)
                {
                    destinationResource = resource;
                    break;
                }
            }

            if (sourceResource != null && destinationResource != null)
            {
                if (sourceResource.ResourceName == destinationResource.ResourceName)
                    base.Drop(state);
            }
        }
        public override bool CanStartResize(DragDropState state)
        {
            return false;
        }
        */
        #endregion
    }
}
